//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"

//一个升序，一个降序
struct Sol{

    void handle(){
        int n;std::cin>>n;
        std::vector<int> arr1(n);
        std::vector<int> arr2(n);
        for(int i=0;i<n;i++){
            std::cin>>arr1[i];
        }
        for(int i=0;i<n;i++){
            std::cin>>arr2[i];
        }
        std::sort(arr1.begin(),arr1.end());
        std::sort(arr2.begin(),arr2.end(),std::greater<int>());
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=arr1[i]*arr2[i];
        }
        printf("%d\n",sum);
        //
    }
};
int main(){
    int a,b,c;
    while(std::cin>>a){
        for(int i=0;i<a;i++){

            Sol().handle();
        }
    }

    return 0;
}